package com.example.project.controller;

import com.example.project.dto.TcdmSecureHazardListRecycleDTO;
import com.example.project.entity.TcdmSecureHazardList;
import com.example.project.entity.TcdmSecureHazardListRecycle;
import com.example.project.service.TcdmSecureHazardListRecycleService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TcdmSecureHazardListRecycle)表控制层
 *
 * @author makejava
 * @since 2024-02-23 15:18:23
 */
@RestController
@CrossOrigin
@RequestMapping("tcdmSecureHazardListRecycle")
public class TcdmSecureHazardListRecycleController {
    /**
     * 服务对象
     */
    @Resource
    private TcdmSecureHazardListRecycleService tcdmSecureHazardListRecycleService;

    /**
     * 分页查询
     *
     * @param tcdmSecureHazardListRecycleDTO 筛选条件
     * @return 查询结果
     */

    @PostMapping("findPage")
    public ResponseEntity<Page<TcdmSecureHazardListRecycle>> queryByPage(@RequestBody TcdmSecureHazardListRecycleDTO tcdmSecureHazardListRecycleDTO ) {
        com.example.project.entity.Page page=tcdmSecureHazardListRecycleDTO.getPage();
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.queryByPage(tcdmSecureHazardListRecycleDTO.getTcdmSecureHazardListRecycle(), PageRequest.of(page.getPage(), page.getSize())));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

    @GetMapping("{id}")
    public ResponseEntity<TcdmSecureHazardListRecycle> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.queryById(id));
    }

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("findAll")
    public List<TcdmSecureHazardListRecycle> findAll() {
        return tcdmSecureHazardListRecycleService.findList();
    }
    /**
     * 新增数据
     *
     * @param tcdmSecureHazardListRecycle 实体
     * @return 新增结果
     */

    @PostMapping("add")
    public ResponseEntity<TcdmSecureHazardListRecycle> add(@RequestBody TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.insert(tcdmSecureHazardListRecycle));
    }

    /**
     * 编辑数据
     *
     * @param tcdmSecureHazardListRecycle 实体
     * @return 编辑结果
     */

    @PutMapping("put")
    public ResponseEntity<TcdmSecureHazardListRecycle> edit(@RequestBody TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.update(tcdmSecureHazardListRecycle));
    }

    /**
     * 删除数据
     *
     * @param tcdmSecureHazardListRecycle 主键
     * @return 删除是否成功
     */

    @DeleteMapping("del")
    public ResponseEntity<Boolean> deleteById(@RequestBody TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.deleteById1(tcdmSecureHazardListRecycle.getTshlrId()));
    }

    @PostMapping("/recover")
    public ResponseEntity<Boolean> recover(@RequestBody TcdmSecureHazardListRecycle tcdmSecureHazardListRecycle){
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.recover(tcdmSecureHazardListRecycle.getTshlrId()));
    }

    @DeleteMapping("/deleteAll")
    public ResponseEntity<Boolean> deleteAll(){
        return ResponseEntity.ok(this.tcdmSecureHazardListRecycleService.deleteAll());
    }
}



